home *** CD-ROM | disk | FTP | other *** search
/ Belgian Amiga Club - ADF Collection / BS1 part 05.zip / BS1 part 5 / IM_3 .adf / Exec / piarc.LZH / graphr.rexx < prev    next >
OS/2 REXX Batch file  |  1992-02-29  |  6KB  |  224 lines

  1. /*
  2.  * GRAPHr.rexx draw a GRAPH in the Image in IM
  3.  *
  4.  *  Written by: Barry Chalmers & Ben Williams
  5.  * Last Update: January 17th, 1992
  6.  *         For: Black Belt Systems image processing series IM, IM F/c, and IP.
  7.  * ---------------------------------------------------------------------------
  8.  *    Revision: 1.01 - see ReadMe file for details on changes to this level
  9.  */
  10.  
  11. /*
  12.  * open rexxsupport.library -- needed for some functions
  13.  */
  14. if ~show('L',"rexxsupport.library") then do
  15.   if addlib('rexxsupport.library',0,-30,0) then do
  16.       /* everything's ok */
  17.     end;
  18.   else do
  19.     say 'We Have A Library Problem, Unable To Load "rexxsupport.library"';
  20.     say 'Cannot operate JPEG.rexx without this library - sorry!';
  21.     exit 10;
  22.     end;
  23.   end;
  24.  
  25. /*
  26.  * This will automatically direct the script to the proper
  27.  * software, if it is running. No matter where the script is
  28.  * launched from.
  29.  */
  30. prtnme = 'IP_Port'; /* assume Image Professional */
  31. if show('P','IP_Port') = 0 then do
  32.   if show('P','IM_Port') = 0 then do
  33.     say "Can't find image processor's ARexx port!!!"; /* not running? */
  34.     say "This script requires IP, IM or IM F/c to run!";
  35.     exit(20);
  36.     end;
  37.   else do
  38.     prtnme = 'IM_Port'; /* That's the thing about assumptions... */
  39.     end;                 /* We make em, user's break em.          */
  40.   end;
  41.  
  42.   /*
  43.    * This code attempts to read a file called "picmdpath" from REXX:
  44.    * If it can't find it, the script will assume that the commands
  45.    * associated with this PI Module are in "c:". If the file exists,
  46.    * the script will look in the path that is specified in the file.
  47.    * If you create this file, you MUST put a complete, correct path
  48.    * in it; if the commands are in a sub-directory, you have to put
  49.    * the trailing slash on the path (like, device:dir/).
  50.    * 
  51.    */
  52.   cmdpath = 'c:';
  53.   if open(fhandle,'rexx:picmdpath','read') then  /* open the file */
  54.     do
  55.       cmdpath = readln(fhandle);
  56.       call close(fhandle);  /* close the file    */
  57.     end
  58.  
  59. /*
  60.  * Get the file name parts
  61.  */
  62.   prevpath = 'ram:';
  63.   if show('C',graphpath) = 1 then do
  64.     prevpath = getclip(graphpath);
  65.     end;
  66.   prevname = 'image';
  67.   if show('C',graphname) = 1 then do
  68.     prevname = getclip(graphname);
  69.     end;
  70.   prevext = '.table';
  71.   if show('C',graphext) = 1 then do
  72.     prevext = getclip(graphext);
  73.     end;
  74.   width = 320;
  75.   if show('C',graphwidth) = 1 then do
  76.     width = getclip(graphwidth);
  77.     end;
  78.   height = 200;
  79.   if show('C',graphheight) = 1 then do
  80.     height = getclip(graphheight);
  81.     end;
  82.  
  83.  
  84. address(prtnme);
  85.  
  86.     options results;
  87.     'filerequest "'||prevpath||'" "'||prevname||'" "'||prevext||'" '||'"Get Table"';
  88.     graphfile = result;
  89.     options;
  90.     call checkfile(graphfile);
  91.     
  92.     options results;
  93.     'asknumber "Width (X)","'||width;
  94.     width = result;
  95.     options;
  96.     call setclip(graphwidth,width);
  97.     
  98.     options results;
  99.     'asknumber "Height (Y)","'||height;
  100.     height = result;
  101.     options;
  102.     call setclip(graphheight,height);
  103.  
  104.     'autoredraw 0';
  105.     'newasprimary '||width||' '||height;
  106.  
  107. options results;
  108. 'jackin';
  109. stuff = result;
  110.  
  111. 'current';
  112. bufdata = result;
  113.  
  114. options;
  115.  
  116. parse var bufdata bname ',' bnum ',' brest
  117.  
  118. 'lockimage '||bnum;
  119. address command cmdpath||'graph '||stuff||' '||graphfile;
  120. 'unlockimage '||bnum;
  121. address(prtnme);
  122.  
  123. 'tofront';
  124. 'redraw';
  125.  
  126. address;
  127.  
  128. exit 0;
  129.  
  130.  
  131. checkfile: 
  132. arg thefile;
  133.   if thefile = 'FR_CANCELLED' then do
  134.     'tofront';
  135.     exit 0;
  136.     end;
  137.   prevpath = gimmepath(thefile);
  138.   call setclip(graphpath,prevpath);
  139.   prevname = gimmename(thefile);
  140.   call setclip(graphname,prevname);
  141.   prevext  = gimmeext(thefile);
  142.   call setclip(graphext,prevext);
  143.   return;
  144.   end
  145.  
  146. /*
  147.  * gimmepath
  148.  *
  149.  * This takes the provided argument and sucks the path out of it, then
  150.  * returns that path to the caller, sans file name.
  151.  */
  152. gimmepath:
  153.   arg fullnamegx;
  154.     tempgx = reverse(fullnamegx);
  155.     lengx = length(fullnamegx);   /* get length of string */
  156.     slashdex = index(tempgx,'/'); /* first occurance of '/' from right */
  157.     colondex = index(tempgx,':');  /* first occurance of ':' from right */
  158.     seploc = 0; /* assumes current dir, no path supplied */
  159.     if slashdex ~= 0 then do /* we assume we are in a DIR */
  160.       seploc = (lengx - slashdex)+1;
  161.       end;
  162.     else do
  163.       if colondex ~= 0 then do /* we assume we are on a device */
  164.         seploc = (lengx - colondex)+1;
  165.         end;
  166.       end;
  167.   gxname = substr(fullnamegx,seploc+1); /* if you ever need it */
  168.   gxpath = left(fullnamegx,seploc);
  169.   return(gxpath);
  170.   end
  171.  
  172.  
  173. gimmename:
  174.   arg fullnamegx;
  175.     tempgx = reverse(fullnamegx);
  176.     lengx = length(fullnamegx);   /* get length of string */
  177.     slashdex = index(tempgx,'/'); /* first occurance of '/' from right */
  178.     colondex = index(tempgx,':');  /* first occurance of ':' from right */
  179.     seploc = 0; /* assumes current dir, no path supplied */
  180.     if slashdex ~= 0 then do /* we assume we are in a DIR */
  181.       seploc = (lengx - slashdex)+1;
  182.       end;
  183.     else do
  184.       if colondex ~= 0 then do /* we assume we are on a device */
  185.         seploc = (lengx - colondex)+1;
  186.         end;
  187.       end;
  188.   extpos = lastpos(".",fullnamegx) - 2;
  189.   if extpos > seploc then do
  190.     gxname = substr(fullnamegx,seploc+1,extpos-seploc+1);
  191.     end;
  192.   else do
  193.     gxname = substr(fullnamegx,seploc+1);
  194.     end;
  195.   return(gxname);
  196.   end
  197.  
  198.  
  199. gimmeext:
  200.   arg fullnamegx;
  201.     tempgx = reverse(fullnamegx);
  202.     lengx = length(fullnamegx);   /* get length of string */
  203.     slashdex = index(tempgx,'/'); /* first occurance of '/' from right */
  204.     colondex = index(tempgx,':');  /* first occurance of ':' from right */
  205.     seploc = 0; /* assumes current dir, no path supplied */
  206.     if slashdex ~= 0 then do /* we assume we are in a DIR */
  207.       seploc = (lengx - slashdex)+1;
  208.       end;
  209.     else do
  210.       if colondex ~= 0 then do /* we assume we are on a device */
  211.         seploc = (lengx - colondex)+1;
  212.         end;
  213.       end;
  214.   extpos = lastpos(fullnamegx,'.');
  215.   if extpos > seploc then do
  216.     gxext = substr(fullnamegx,extpos+1);
  217.     end
  218.   else do
  219.     gxext = '';
  220.     end
  221.   return(gxext);
  222.   end
  223.  
  224.